<?php namespace App\Admin\Experience\Enter\Listeners;

use App\Core\Exceptions\InputError;
use App\Core\Service\Listeners\DeleteListener as Base;
use Input;
use DB;


class DeleteListener extends Base {
    
    public function onDeleteSaving(){
        $id = Input::get('id');
        $ids = Input::get('ids');
        $IDs = explode(',',$ids);

        DB::table('settled_in')->where('id','=',$id)->update(['sort' => '10000']);
        DB::table('settled_in')->whereIn('id',$IDs)->update(['sort' => '10000']);

        $entertwo = DB::table('settled_in')->where('is_delete','=','0')->where('sort','!=','10000')->get();

        $ids=[];
        foreach($entertwo as $k=>$v){
            $ids[] = $v->id;
        }

        for($i=0;$i<count($entertwo);$i++){
            DB::table('settled_in')->where('id',$ids[$i])
                ->update([
                    'sort' => $i+1
                ]);
        }
    }


}